package com.zhz.service.provider;

import java.util.List;

import com.zhz.dao.provider.ProviderMapper;
import com.zhz.entity.Provider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service("providerService")
public class ProviderServiceImpl implements ProviderService {
    @Autowired
    private ProviderMapper providerMapper;

    @Override
    public int getCountOfProviders() {
        try {
            return providerMapper.count();
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public List<Provider> findAllProviders() {
        try {
            return providerMapper.getProviderList();
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public List<Provider> findProvidersByName(String proName) {
        try {
            return providerMapper.getProviderListByName(proName);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public int addNewProvider(Provider provider) {
        int count = -1;
        try {
            count = providerMapper.add(provider);
            // 模拟异常，进行回滚
            // int i = 2/0;
            return count;
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public int modifyProvider(Provider provider) {
        int count = -1;
        try {
            count = providerMapper.modify(provider);
            // 模拟异常，进行回滚
            // int i = 2/0;
            return count;
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public int deleteProvider(Integer delId) {
        int count = -1;
        try {
            count = providerMapper.deleteProviderById(delId);
            // 模拟异常，进行回滚
            // int i = 2/0;
            return count;
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }
}
